<!--
 * @Author: 偻儸小卒[EdisonLiu_]
 * @Date: 1970-01-01 08:00:00
 * @LastEditors: 偻儸小卒[EdisonLiu_]
 * @LastEditTime: 2020-03-23 14:30:03
 * @Description: 
 -->
<template>
  <div >
     
        <main>
             <textarea
              name
              id
              cols="30"
              rows="10"
              v-model="inputjs"
              placeholder="请输入密文"
            ></textarea>
            <textarea name id cols="30" rows="10" v-model="outputjs"></textarea>
            <button @click="js_beautify">解密</button>
        </main>
      </div>
    
</template>
<script>
//js美化
import { js_beautify } from "js-beautify";
//下面是js解密相关
import { P_A_C_K_E_R, Urlencoded, MyObfuscate } from "../../publicjs/index";
import { debug, debuglog } from "util";

export default {
  name: "index",
   components: {
  },
  data() {
    return {
      inputjs: "",
      outputjs: "",
     
    };
  },
  created: function() {
    
  },
  methods: {
    //js美化
    js_beautify() {
      let source = this.inputjs,
        output,
        opts = {};

      opts.indent_size = 4;
      opts.indent_char = " ";
      opts.max_preserve_newlines = 5;
      opts.preserve_newlines = opts.max_preserve_newlines !== "-1";
      opts.keep_array_indentation = false;
      opts.break_chained_methods = false;
      opts.indent_scripts = "normal";
      opts.brace_style = "collapse";
      opts.space_before_conditional = true;
      opts.unescape_strings = false;
      opts.jslint_happy = false;
      opts.wrap_line_length = 0;
      opts.space_after_anon_function = true;
      // //执行解密方法
      source = this.unpacker_filter(source, this);

      let reg = RegExp(/^eval/);
      //如果存在eval方法则
      if (reg.test(source)) {
        //下面是面对eval 最简单粗暴的破解方法 【没有那些花里胡哨的骚操作去掉方法头直接跑一遍然后把结果返回回去即可】
        source = source.replace(/^eval/, "");
        source = eval(source);
      }
      this.outputjs = js_beautify(source, opts);
    },

    //js解密方法
    unpacker_filter: function(source) {
      var trailing_comments = "",
        comment = "",
        unpacked = "",
        found = false;

      do {
        found = false;
        if (/^\s*\/\*/.test(source)) {
          found = true;
          comment = source.substr(0, source.indexOf("*/") + 2);
          source = source.substr(comment.length).replace(/^\s+/, "");
          trailing_comments += comment + "\n";
        } else if (/^\s*\/\//.test(source)) {
          found = true;
          comment = source.match(/^\s*\/\/.*/)[0];
          source = source.substr(comment.length).replace(/^\s+/, "");
          trailing_comments += comment + "\n";
        }
      } while (found);

      var unpackers = [P_A_C_K_E_R, Urlencoded, MyObfuscate];
      for (var i = 0; i < unpackers.length; i++) {
        if (unpackers[i].detect(source)) {
          unpacked = unpackers[i].unpack(source);
          if (unpacked != source) {
            source = this.unpacker_filter(unpacked);
          }
        }
      }
      return trailing_comments + source;
    },
  }
};
</script>
